//index.js
//获取应用实例
const app = getApp();
var OPEN_ID = wx.getStorageSync('wx_open_id');//储存获取到openid  
var SESSION_KEY = '';//储存获取到session_key  
const user = wx.getStorageSync("user");
const user_token = (wx.getStorageSync('user_token'));
const base_url = app.globalData.base_url;
const util = require('../../utils/util.js');
Page({

  onLoad: function (options) {

    // var that = this;
    // wx.getStorage({
    //   key: 'userinfo',
    //   success: function (res) {
    //     that.globalData.user_info = res.data;
    //   },
    //   fail: function () {
    //     app.login();
    //   }
    // });
    // console.log('12345')
    // console.log(that.globalData.user_info)

  
    var id = decodeURIComponent(options.q);

      var regNum = new RegExp('[0-9]', 'g');
  
      if (regNum.exec(id)) {
        id = id.substr(52);
        
        this.topage(id)
      }
      

  },

  topage: function (id) {
    wx.showLoading({
      title: '加载中',
      success: () => {
        wx.request({
          url: base_url + '/Qcode/index',
          method: 'POST',
          data: {
            'user_token': JSON.parse(wx.getStorageSync("user")).user_token,
            'id': id
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: res => {
            console.log(res)
            if (res.data.success == '1') {
              if (res.data.code == '0') {
                wx.redirectTo({
                  url: '../carInfo/index?id=' + id
                })
              } else if (res.data.code == '800') {
                wx.redirectTo({
                  url: '../bindPhone/index?id=' + id
                })
              } else if (res.data.code == '801') {
                wx.redirectTo({
                  url: '../myInfo/index'
                })
              }
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
            }
          }
        })
      }
    })
  },
  globalData: {
    user_info: null,
  }
})
